package javabase.collection.list.search;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;



/**
 * <pre>
 *   Title: ListSearch2.java
 *   Description: 
 *   Copyright: yundaex.com Copyright (c) 2013
 *   Company: 上海韵达货运有限公司
 * </pre>
 * 
 * @author liuzhaoqing
 * @version 1.0
 * @date 2014年11月6日
 */
public class ListRetrieve2 {
	public static void main(String[] args) {
		List<Person> listFromDB = new ArrayList<Person>(8);
		
		listFromDB.add(new Person("张三","总经理",1001));
		listFromDB.add(new Person("李四","工程师",1002));
		listFromDB.add(new Person("王五","副总经理",1003));
		listFromDB.add(new Person("小六","职员",1004));
		listFromDB.add(new Person("小毛","音响",1005));
		listFromDB.add(new Person("啊涛","灯光",1006));
		listFromDB.add(new Person("小飞","卫生",1007));
		listFromDB.add(new Person("二丫","人事",1008));
		
		List<Person> listFromExcel = new ArrayList<Person>(5);
		
		listFromExcel.add(new Person("张三","总经理",1001));
		listFromExcel.add(new Person("李四","工程师",1002));
		listFromExcel.add(new Person("小八","副总经理",1003));
		listFromExcel.add(new Person("小九","职员",1004));
		listFromExcel.add(new Person("小十","音响",1005));
		
		if (Collections.disjoint(listFromDB, listFromExcel)) {
			System.out.println("存在交集");
		}
		
		Set<Person> set =new HashSet<Person>();
		
		Person per = null;
		for (int i = 0, size = listFromExcel.size(); i < size; i++) {
			if (listFromDB.contains(per = listFromExcel.get(i))) {
				set.add(per);
			}
		}
		
		listFromExcel.clear();
		listFromExcel.addAll(set);
		
		for (int i = 0, size = listFromExcel.size(); i < size; i++) {
			System.out.println(listFromExcel.get(i));
		}
	}

}
